<template>
  <div class="tab-bar-item" @click="itemClick">
      
      <div v-if="!isActive"><slot name="item-icon"></slot></div>
      <div v-else><slot name="item-iconactive"></slot></div>
      <div :class="{active:isActive}"><slot name="item-text"></slot></div>
      
    </div>
</template>

<script>
export default {
    name:"TabBarItem",
    props: {
        path:String
    },
    data () {
        return {
            // isActive:true
        }
    },
    methods: {
        itemClick(){
            this.$router.push(this.path)
        }
    },
    computed: {
        // 计算属性动态改变选中的路由颜色
        isActive(){
            // return this.$route.path===this.path?true:false
            return this.$route.path.indexOf(this.path) !== -1
            // return this.$route.path==this.path
        }
    }
}
</script>

<style lang='scss' scoped>
.tab-bar-item{
  width: 25%;
  text-align: center;
  height: 49px;
  margin-top: 14px;
  font-size: 14px;

//   width: 100%;
}
.tab-bar-item img{
    
    width: 24px;
    height: 24px;
    vertical-align: middle;
}
.active{
    color: red;
}
</style>